import {
	CRYPTO_JS_KEY,
	CRYPTO_JS_IV
} from './env'
var CryptoJS = require("./aes.js")
var KEY = '0544508217063078';
var IV = '8NONwyJtHesysWpM';

// 加密
function encrypt(str) {
	var key = CryptoJS.enc.Utf8.parse(KEY);
	var iv = CryptoJS.enc.Utf8.parse(IV);
	var encrypted = CryptoJS.AES.encrypt(str, key, {
		iv: iv,
		mode: CryptoJS.mode.CBC,
		padding: CryptoJS.pad.Pkcs7
	});
	return encrypted.toString();
}

// 解密
function decrypt(str) {
	var key = CryptoJS.enc.Utf8.parse(KEY);
	var iv = CryptoJS.enc.Utf8.parse(IV);
	var decrypted = CryptoJS.AES.decrypt(str, key, {
		iv: iv,
		padding: CryptoJS.pad.Pkcs7
	});
	return decrypted.toString(CryptoJS.enc.Utf8);
}

export {
	encrypt,
	decrypt
}